home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok29.lha
/
Strings
/
StringForm.mod
< prev
next >
Wrap
Text File
|
1993-08-15
|
3KB
|
142 lines
(**********************************************************************
:Program. StringForm.mod
:Contents. string formatting procedures
:Author. Nicolas Benezan [bne]
:Address. Postwiesenstr. 2, D7000 Stuttgart 60
:Phone. 711/333679
:Copyright. Public Domain
:Language. Modula-2
:Translator. M2Amiga A+L V3.2d
:History. V1.0a [bne] 11.May.1989
**********************************************************************)
IMPLEMENTATION MODULE StringForm;
FROM StringOps IMPORT Length, DeleteSubString;
CONST
nul=CHR(0);
space=" ";
PROCEDURE AppendBlanks(VAR String:ARRAY OF CHAR;
Width:INTEGER);
VAR
Pos,Max:INTEGER;
BEGIN
IF Width<=HIGH(String) THEN
Max:=Width-1;
ELSE
Max:=HIGH(String);
END;
Pos:=Length(String);
WHILE Pos<=Max DO
String[Pos]:=space;
INC(Pos);
END;
IF Pos<=HIGH(String) THEN
String[Pos]:=nul;
END;
END AppendBlanks;
PROCEDURE LeftInsertChar(VAR String:ARRAY OF CHAR;
Char:CHAR;
Num:INTEGER);
VAR
Pos,Max:INTEGER;
BEGIN
Max:=Length(String)-1+Num;
IF Max>HIGH(String) THEN
Max:=HIGH(String);
END;
FOR Pos:=Max-Num TO Num BY -1 DO
String[Max]:=String[Pos];
DEC(Max);
END;
DEC(Num);
IF Num<=HIGH(String) THEN
FOR Pos:=0 TO Num DO
String[Pos]:=Char;
END;
END;
END LeftInsertChar;
PROCEDURE Indent(VAR String:ARRAY OF CHAR;
Margin:INTEGER);
BEGIN
LeftInsertChar(String,space,Margin);
END Indent;
PROCEDURE CenterAdjust(VAR String:ARRAY OF CHAR;
Width:INTEGER);
VAR
Len:INTEGER;
BEGIN
Len:=Length(String);
IF Len<Width THEN
Indent(String,(Width-Length(String)) DIV 2);
AppendBlanks(String,Width);
END;
END CenterAdjust;
PROCEDURE CutBlanks(VAR String:ARRAY OF CHAR);
VAR
Pos:INTEGER;
BEGIN
Pos:=0;
WHILE (Pos<=HIGH(String)) AND (String[Pos]=space) DO
INC(Pos);
END;
DeleteSubString(String,0,Pos);
Pos:=Length(String)-1;
WHILE (Pos>=0) AND (String[Pos]=space) DO
DEC(Pos);
END;
INC(Pos);
IF Pos<=HIGH(String) THEN
String[Pos]:=nul;
END;
END CutBlanks;
PROCEDURE RightAdjust(VAR String:ARRAY OF CHAR;
Width:INTEGER);
VAR
Len:INTEGER;
BEGIN
CutBlanks(String);
Len:=Length(String);
IF Len<Width THEN
Indent(String,Width-Len);
END;
END RightAdjust;
PROCEDURE EmptyString(String:ARRAY OF CHAR):BOOLEAN;
VAR
Pos:INTEGER;
BEGIN
FOR Pos:=0 TO HIGH(String) DO
IF String[Pos]=nul THEN
RETURN TRUE;
ELSIF String[Pos]#space THEN
RETURN FALSE;
END;
END;
RETURN TRUE;
END EmptyString;
PROCEDURE LeftInsertZeroes(VAR String:ARRAY OF CHAR;
Width:INTEGER);
VAR
Len:INTEGER;
BEGIN
CutBlanks(String);
Len:=Length(String);
IF Len<Width THEN
LeftInsertChar(String,"0",Width-Len);
END;
END LeftInsertZeroes;
END StringForm.